home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / filutil / ygrep401.zip / DOS.C < prev    next >
C/C++ Source or Header  |  1995-02-03  |  5KB  |  154 lines

  1. #if    !defined( lint )
  2. static    char *sccsid = "@(#)dos.c    (C) Yves Roumazeilles    95/02/03";
  3. #endif
  4. #pragma    warning(disable:4001)
  5.  
  6. /*
  7. //   Test program for DOS libs
  8. //
  9. //   Just compile it with the appropriate model (corresponding to the one
  10. //   used by the library you selected:
  11. //    SYGREP.LIB (Microsoft) and SYGREPB.LIB (Borland) are Small model;
  12. //    CYGREP.LIB (Microsoft) and CYGREPB.LIB (Borland) are Compact model;
  13. //    MYGREP.LIB (Microsoft) and MYGREPB.LIB (Borland) are Medium model;
  14. //    LYGREP.LIB (Microsoft) and LYGREPB.LIB (Borland) are Large model;
  15. //    HYGREP.LIB (Microsoft) is Huge model.
  16. //
  17. //   Version 2.0
  18. */
  19.  
  20. #define    STRICT    
  21. #include    <windows2.h>
  22. #include    <stdio.h>
  23. #include    <malloc.h>
  24. #include    "ygrep.h"
  25.  
  26.  
  27. #define    CHECK(a,b,s)    if((a)!=(b)) {fprintf(stderr,"\n---"s"->(%d)\n",(a));return(-1);} else{fprintf(stderr,".");}
  28.  
  29.  
  30.  
  31. LPCSTR    test[] = {
  32.     /*0*/    "include",
  33.     /*1*/    "includi",
  34.     /*2*/    "includeINCLUDE",
  35.     /*3*/    "toto",
  36.     /*4*/    "tototo",
  37.     /*5*/    "totototo",
  38.     /* */    "" };
  39.  
  40.  
  41. main()
  42. {
  43.     int        iVal;
  44. /*    AGREPINFO    aGI;    */
  45.     LPAGREPINFO    pGI;
  46.     LPRGREPINFO    pRGI;
  47.     char*        pTemp;
  48.     char*        pSubs = "012345678901234567890123456789";
  49.     char*        pDest = "012345678901234567890123456789";
  50.  
  51.     printf("*** YGrep Search Engine diags level 1 ***\n\n");
  52.     printf("YGrepVersion: 0x%04x\n", YGrepVersion());
  53.     printf("Starting!\n");
  54.  
  55.     pGI = (LPAGREPINFO)calloc(1, sizeof(AGREPINFO));
  56. /*    pGI = &aGI;    */
  57.     
  58.     CHECK( AGrepInit(pGI), TRUE, "init" );
  59.     
  60.     // k=0 mismatch...
  61.     CHECK( CompileAGrep((LPCSTR)test[1], 0, TRUE,  pGI), AGERR_NO_ERROR, "cmp0" );
  62.     // ...0 matche(s)
  63.     CHECK( AGrep((LPCSTR)test[2], pGI), 0, "ag0" );
  64.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  65.  
  66.     // k=1 mismatch...
  67.     CHECK( CompileAGrep((LPCSTR)test[1], 1, TRUE,  pGI), AGERR_NO_ERROR, "cmp1" );
  68.     // ...1 matche(s)
  69.     CHECK( AGrep((LPCSTR)test[2], pGI), 1, "ag1" );
  70.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  71.  
  72.     // k=1 mismatch, but no case...
  73.     CHECK( CompileAGrep((LPCSTR)test[1], 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  74.     // ...2 matche(s)
  75.     CHECK( AGrep((LPCSTR)test[2], pGI), 2, "ag2" );
  76.     CHECK( AGrepSubsBuild("-&-", pSubs, 30, pGI), AGERR_NO_ERROR, "su0" );
  77.     CHECK( strcmp(pSubs,"-include-"), 0, "su1" );
  78.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  79.  
  80.     // ElectUnltd bug?
  81.     CHECK( CompileAGrep((LPCSTR)"Bob", 5, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  82.     //fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben", pGI) );
  83.     //fprintf( stderr, "%3d", AGrep((LPCSTR)test[2], pGI) );
  84.     //fprintf( stderr, "%3d", AGrep((LPCSTR)"Ben τa alors, tiens !", pGI) );
  85.     CHECK( AGrep((LPCSTR)"Ben", pGI), 3, "eu1" );
  86.     CHECK( AGrep((LPCSTR)test[2], pGI), 14, "eu2" );
  87.     CHECK( AGrep((LPCSTR)"Ben τa alors, tiens !", pGI), 21, "eu3" );
  88. #define    LONGUEUR    2300
  89.     pTemp = (char*)calloc(LONGUEUR,sizeof(char));
  90.     if( pTemp==NULL )
  91.         fprintf(stderr, "!");
  92.     else {
  93.         for( iVal=0; iVal<LONGUEUR-1; iVal++ )
  94.             pTemp[iVal] = '!';
  95.         pTemp[LONGUEUR-1]='\0';
  96.         /*fprintf(stderr,"*");*/
  97.         CHECK( AGrep((LPCSTR)pTemp, pGI), (int)strlen(pTemp), "eu4" );
  98.     }
  99.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  100.  
  101.     CHECK( CompileAGrep((LPCSTR)"Bob", 1, FALSE, pGI), AGERR_NO_ERROR, "cmp2" );
  102.     CHECK( AGrep((LPCSTR)pTemp, pGI), 0, "eu5" );
  103.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  104.     free(pTemp);
  105.  
  106.     // January bug check
  107.     CHECK( CompileAGrep((LPCSTR)test[3], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp3" );
  108.     CHECK( AGrep((LPCSTR)test[4], pGI), 2, "to1" );
  109.     CHECK( AGrep((LPCSTR)test[5], pGI), 3, "to2" );
  110.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  111.     CHECK( CompileAGrep((LPCSTR)test[4], 0, TRUE, pGI), AGERR_NO_ERROR, "cmp4" );
  112.     CHECK( AGrep((LPCSTR)test[5], pGI), 2, "to3" );
  113.     CHECK( AGrepEmpty(pGI), TRUE, "emp" );
  114.  
  115.     free(pGI);
  116.  
  117.     pRGI = (LPRGREPINFO)calloc(1, sizeof(RGREPINFO));
  118.     free(pRGI);
  119.     
  120.     printf("\nEnding!\n");
  121.     return 0;
  122. }
  123.  
  124.  
  125. /*
  126. //    Some comments. Without any order...
  127. */
  128.  
  129. /*
  130. //    Nobody ever reads what is in the sample source code. However, you
  131. //    will be able to know why there is no AGREPINFO variable built in
  132. //    an automatic variable inside main(). It would have been nice and
  133. //    simpler than allocating it from the heap with calloc(). Well...
  134. //    Yes but there is quite a problem with large data structures like
  135. //    this one when they are built from the stack. E.g. with Borland C++
  136. //    v4.0, you would have to increase manually the stack for the simplest
  137. //    program - like this one - to operate smoothly.
  138. //    In the original version, I was building an AGREPINFO aGI variable
  139. //    as an automatic variable (it may still be present as a code comment),
  140. //    but this had a too large impact on code and data size for some of the
  141. //    memory models. See below.
  142. */
  143.  
  144. /*
  145. //    You must also remember that the YGrep Search Engine is a rather large
  146. //    set of routines and data. For real world applications it is highly
  147. //    improbable that you will be able to use the Small or Compact memory
  148. //    models. The data segment is too small for that.
  149. //    This size limitation can also appear when compiling applications with
  150. //    full debug information. E.g. Borland C++ 4.0 insisted on producing a
  151. //    stack overflow on entering main() [before reaching the first C code
  152. //    line.]
  153. */
  154.